﻿using System;
using System.Collections.Generic;
using Terraria.Achievements;

namespace Terraria.GameContent.Achievements
{
	// Token: 0x0200046A RID: 1130
	public class ItemPickupCondition : AchievementCondition
	{
		// Token: 0x06002669 RID: 9833 RVA: 0x0001AB4E File Offset: 0x00018D4E
		private ItemPickupCondition(short itemId) : base("ITEM_PICKUP_" + itemId)
		{
			this._itemIds = new short[]
			{
				itemId
			};
			ItemPickupCondition.ListenForPickup(this);
		}

		// Token: 0x0600266A RID: 9834 RVA: 0x0001AB7C File Offset: 0x00018D7C
		private ItemPickupCondition(short[] itemIds) : base("ITEM_PICKUP_" + itemIds[0])
		{
			this._itemIds = itemIds;
			ItemPickupCondition.ListenForPickup(this);
		}

		// Token: 0x0600266B RID: 9835 RVA: 0x00491A7C File Offset: 0x0048FC7C
		private static void ListenForPickup(ItemPickupCondition condition)
		{
			if (!ItemPickupCondition._isListenerHooked)
			{
				AchievementsHelper.OnItemPickup += ItemPickupCondition.ItemPickupListener;
				ItemPickupCondition._isListenerHooked = true;
			}
			for (int i = 0; i < condition._itemIds.Length; i++)
			{
				if (!ItemPickupCondition._listeners.ContainsKey(condition._itemIds[i]))
				{
					ItemPickupCondition._listeners[condition._itemIds[i]] = new List<ItemPickupCondition>();
				}
				ItemPickupCondition._listeners[condition._itemIds[i]].Add(condition);
			}
		}

		// Token: 0x0600266C RID: 9836 RVA: 0x00491B00 File Offset: 0x0048FD00
		private static void ItemPickupListener(Player player, short itemId, int count)
		{
			if (player.whoAmI != Main.myPlayer)
			{
				return;
			}
			if (ItemPickupCondition._listeners.ContainsKey(itemId))
			{
				List<ItemPickupCondition> list = ItemPickupCondition._listeners[itemId];
				foreach (ItemPickupCondition itemPickupCondition in list)
				{
					itemPickupCondition.Complete();
				}
			}
		}

		// Token: 0x0600266D RID: 9837 RVA: 0x0001ABA3 File Offset: 0x00018DA3
		public static AchievementCondition Create(params short[] items)
		{
			return new ItemPickupCondition(items);
		}

		// Token: 0x0600266E RID: 9838 RVA: 0x0001ABAB File Offset: 0x00018DAB
		public static AchievementCondition Create(short item)
		{
			return new ItemPickupCondition(item);
		}

		// Token: 0x0600266F RID: 9839 RVA: 0x00491B74 File Offset: 0x0048FD74
		public static AchievementCondition[] CreateMany(params short[] items)
		{
			AchievementCondition[] array = new AchievementCondition[items.Length];
			for (int i = 0; i < items.Length; i++)
			{
				array[i] = new ItemPickupCondition(items[i]);
			}
			return array;
		}

		// Token: 0x040041A1 RID: 16801
		private const string Identifier = "ITEM_PICKUP";

		// Token: 0x040041A2 RID: 16802
		private static Dictionary<short, List<ItemPickupCondition>> _listeners = new Dictionary<short, List<ItemPickupCondition>>();

		// Token: 0x040041A3 RID: 16803
		private static bool _isListenerHooked = false;

		// Token: 0x040041A4 RID: 16804
		private short[] _itemIds;
	}
}
